<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>前锋图书管理系统</title>
    <link rel="stylesheet" href="/css/public.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
    <link rel="stylesheet" href="/js/layui/css/layui.css"  media="all">
</head>
<style>
    html,body{
        width: 100%;
        height: 100%;
    }
    .homeWrap{
        width: 100%;height: 100%;
        padding-top: 76px;position: relative;box-sizing: border-box;overflow: hidden;
    }
    .homeWrap div{box-sizing: border-box;}
    .hide{
        display: none;
    }
    .detelebox button{
        width: 50px;
        height: 28px;
        margin-top: 10px;
        margin-left: 50px;
        display: inline-block;
        border: 1px solid #679e43;
        background: linear-gradient(to bottom,#baf076,#a2d866,#9cd055,#8dc838,#8bc93a);
        line-height: 28px;
        text-align: center;
        border-radius: 4px;
        font-weight: bold;
        color: #fff;
    }
    #addgroup{
        height:30px;width:100px;margin-left: 0px;background-color: #47ACF1;border-radius: 4px;color: #fff;
    }
    #addgroup:hover{cursor: pointer;}
    .publicMian,.left{height: 100%;}
    .homeHeader{width: 100%; position: absolute;left: 0;top: 0;}
</style>
<body>
<div class="homeWrap">
    <div class="homeHeader">
            <!--头部-->
        <header class="publicHeader">
            <h1>前锋图书管理系统</h1>
            <div class="publicHeaderR">
                <p><span>下午好！</span><span style="color: #fff21b"> Admin</span> , 欢迎你！</p>
                <a href="/admin/index/signOut">退出</a>
            </div>
        </header>
    <!--时间-->
        <section class="publicTime">
            <span id="time">2015年1月1日 11:11  星期一</span>
        </section>
    </div>

<!--主体内容-->
    <section class="publicMian">
        <div class="left">
            <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
            <nav>
                <ul class="list">
                    <li><a href="/admin/home/home">首页</a></li>
                    <li><a href="/admin/home/borrowingmanagement">借阅管理</a></li>
                    <li><a href="/admin/home/bookrecord">图书记录</a></li>
                    <li><a href="/admin/home/bookadd">图书添加</a></li>
                    <li><a href="/admin/scrollmember/scroll">滚屏</a></li>
                    <li><a href="/admin/scrollmember/member">会员管理</a></li>
                    <li><a href="/admin/home/editpass">修改密码</a></li>
                    <li id="active"><a href="/admin/home/groupbuy">团队来源</a></li>
                </ul>
            </nav>
        </div>

        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>团队来源</span>
            </div>
            <div class="search" style="padding-left: 0px;">
                <button id="addgroup" onclick="addgroupinfo()">添加团队</button>
            </div>
            <!--账单表格 样式和供应商公用-->
            <div class="record">

            </div>
            <div class="pagePage" style="top: 800px;">
                <div class="page_control">
                    <div class="pagination"></div>
                </div>
            </div>
        </div>

    </section>
</div>

<script src="/js/jquery.js"></script>
<script src="/js/js.js"></script>
<script src="/js/time.js"></script>
<script src="/js/layui/layui.js"></script>
<script src="/js/jquery.paging.js"></script>
<script src="/js/layer/layer.js"></script>
<script>
    // 分页
    $('.pagination').paging({
        total: '',
        currentPage: '',
        showPage: 5,        //显示的页数
        animation: false,
        showJump: false,
        ajaxSubmitType: 'post',
        simpleType: 1,
        url: '/admin/home/groupbuy',
        idParameter: "page",
        ajaxData: {'pageSize': 5},
        beforeAjaxSubmit: function () {
            PageAPI.AddAjaxData({"pageSize": $(".pageSize").val()});
        },
        ajaxSubmitBack: function (data) {
            // console.log(data.data);
            $('.record').empty();
            var orderinfo = data.data;
            if(orderinfo=='' ||orderinfo==undefined){
                $(".record").html(' <h2 style="text-align: center;padding-top:120px;height: 166px;color: red;">暂无数据</h2>');
                $(".pagination").hide();
            }else{
                $(".pagination").show();
                var infohtml="";
                infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">'
                infohtml += '<tr class="firstTr">'
                infohtml += '<th>团队名</th>'
                infohtml += '<th>团队介绍</th>'
                infohtml += '<th>操作</th>'
                infohtml += '</tr>'
                $.each(orderinfo,function(index,value){
                    infohtml += '<tr>'
                    infohtml += '<td class="tdclass">'+value['title']+'</td>'
                    infohtml += '<td>'+value['content']+'</td>'
                    infohtml += '<td>'
                    infohtml += '<input type="button" onclick="editBooksInsi('+value['id']+')" value="编辑" class="anniu"/>';
                    infohtml += '<input type="button" onclick="deleteRecord('+value['id']+')" value="删除" class="anniu"/>';
                    infohtml += '</td>'
                    infohtml += '</tr>'
                });
                infohtml += '</table>';
                $(".record").html(infohtml)
            }
        },
        ajaxFormatBack: function (data) {
            data.total = data.totalpage;
            data.currentPage = data.currentPage;
        }
    });
    


    // 编辑图书
    var bookid;
    var imgUrl = '';   // 图片地址
    function editBooksInsi(id){
        $.ajax({
            url:'/admin/home/editgroup',
            type:'POST',
            data:{id:id},
            success:function(res){
                console.log(res);
                layui.use('upload', function(){
                    var $ = layui.jquery
                        ,upload = layui.upload;
                    layer.open({
                        type: 1,
                        title:'请编辑图书信息',
                        area: ['813px','604px','-116.5px','334.5px'],
                        shadeClose: true, //点击遮罩关闭
                        content:'<div class="providerAdd" style="width: 90%;">' +
                        '<div>' +
                        '<label for="money">团队名：</label>' +
                        '<input type="text" name="money" id="money" value="'+res['title']+'" style="padding:0px 10px;" required/>' +
                        '</div>' +
                        
                        '<label style="bottom:280px;float:left;">团队介绍：</label>' +
                        '<div>' +
                        '<textarea name="money" id="bookFrom" style="width:262px;height:300px;padding:10px;border-radius:4px;border:1px solid #4987c0;" required>'+res['content']+'</textarea>'+
                        '</div>' +
                        '<div class="providerAddBtn" style="width:100%;margin-left:0px;">' +
                        '<input type="button" value="确认更改" onclick="editBook('+id+')" style="display:block;width: 130px;margin:0 auto;"/>' +
                        '</div>' +
                        '</div>'
                    });
                });
            }
        });
        bookid = id;
    }


    // 修改图书
    function editBook(id){
        var grouptitle = $("#money").val();
        var groupcontent = $("#bookFrom").val();
        // alert(groupcontent)
        if(grouptitle == ''){
            layer.msg('请填写团队名称');
        }else if(groupcontent == ''){
            layer.msg('请填写团队介绍');
        }else{
            $.ajax({
                url:'/admin/home/doeditgroup',
                type:'POST',
                data:{
                    id:id,
                    title:grouptitle,
                    content:groupcontent
                },
                success:function(res){
                    console.log(res)
                    if(res == 1){
                        layer.msg('编辑成功');
                        $('.providerAdd').addClass('hide');
                        window.location.href='/admin/home/groupbuy';
                    }else{
                        layer.msg('编辑失败');
                        $('.providerAdd').addClass('hidden');
                    }
                },
                error:function(){

                }
            });
        }

    }

    // 弹出删除点击确定
    function deleteRecord(id){
        $.ajax({
            url:'/admin/home/deletegroup',
            type:'POST',
            data:{
                id:id,
            },
            success:function(res){
                console.log(res)
                if(res == 1){
                    layer.msg('删除成功！', {
                        icon: 1,
                        time: 1000
                        }, function () {
                            window.location.href = "/admin/home/groupbuy";
                        });
                }else{
                    layer.msg('删除失败！', {
                        icon: 2,
                        time: 1000
                        }, function () {
                            window.location.href = "/admin/home/groupbuy";
                        });
                }
            },
            error:function(){

            }
        });
    }


    //添加团队
     function addgroupinfo(){
        $.ajax({
            url:'/admin/home/addgroup',
            type:'POST',
            data:{},
            success:function(res){
                console.log(res);
                layui.use('upload', function(){
                    var $ = layui.jquery
                        ,upload = layui.upload;
                    layer.open({
                        type: 1,
                        title:'请编辑图书信息',
                        area: ['813px','604px','-116.5px','334.5px'],
                        shadeClose: true, //点击遮罩关闭
                        content:'<div class="providerAdd" style="width: 90%;">' +
                        '<div>' +
                        '<label for="money">团队名：</label>' +
                        '<input type="text" name="money" id="grouptitle" value="" style="padding:0px 10px;" required/>' +
                        '</div>' +
                        
                        '<label style="bottom:280px;float:left;">团队介绍：</label>' +
                        '<div>' +
                        '<textarea name="money" id="groupcontent" style="width:262px;height:300px;padding:10px;border-radius:4px;border:1px solid #4987c0;" required></textarea>'+
                        '</div>' +
                        '<div class="providerAddBtn" style="width:100%;margin-left:0px;">' +
                        '<input type="button" value="确认添加" onclick="addgroup()" style="display:block;width: 130px;margin:0 auto;"/>' +
                        '</div>' +
                        '</div>'
                    });
                });
            }
        });
    }

    //添加团队来源数据
    function addgroup(){
        var grouptitle = $("#grouptitle").val();
        var groupcontent = $("#groupcontent").val();
        if (grouptitle=='') {
            layer.msg('请填写团队名称');
        }else if (groupcontent=='') {
            layer.msg('请填写团队介绍');
        }else{
            $.ajax({
                url:'/admin/home/addgroupdata',
                type:'POST',
                data:{
                    title:grouptitle,
                    content:groupcontent
                },
                success:function(res){
                    console.log(res)
                    if(res == 1){
                        layer.msg('添加成功');
                        $('.providerAdd').addClass('hide');
                        window.location.href='/admin/home/groupbuy';
                    }else{
                        layer.msg('添加失败');
                        $('.providerAdd').addClass('hidden');
                    }
                },
                error:function () {
                    layer.alert('添加失败！', {icon: 2}, function () {
                    layer.closeAll();
                    })
                }
            });
        }
    }
   
</script>
</body>
</html>